<div class="content-section introduction">
    <div>
        <span class="feature-title">Dropdown</span>
        <span>Dropdown is used to select an item from a collection of options. Custom content support and filtering are the notable features.</span>
    </div>
</div>

<div class="content-section implementation">
    <h3 class="first">Single</h3>
    <p-dropdown [options]="cities" [(ngModel)]="selectedCity" placeholder="Select a City" optionLabel="name" [showClear]="true"></p-dropdown>
    <p>Selected City: {{selectedCity ? selectedCity.name : 'none'}}</p>
    
    <h3>Editable</h3>
    <p-dropdown [options]="cars" [(ngModel)]="selectedCar1" [style]="{'width':'150px'}" editable="true" placeholder="Select a Brand"></p-dropdown>
    <p>Selected Car: {{selectedCar1 || 'none'}}</p>
    
    <h3>Content with Filters</h3>
    <p-dropdown [options]="cars" [(ngModel)]="selectedCar2" [style]="{'width':'150px'}" filter="true">
        <ng-template let-item pTemplate="selectedItem">
            <img src="assets/showcase/images/demo/car/{{item.label}}.png" style="width:16px;vertical-align:middle" />
            <span style="vertical-align:middle">{{item.label}}</span>
        </ng-template>
        <ng-template let-car pTemplate="item">
            <div class="ui-helper-clearfix" style="position: relative;height: 25px;">
                <img src="assets/showcase/images/demo/car/{{car.label}}.png" style="width:24px;position:absolute;top:1px;left:5px"/>
                <div style="font-size:14px;float:right;margin-top:4px">{{car.label}}</div>
            </div>
        </ng-template>
    </p-dropdown>
    <p>Selected Car: {{selectedCar2||'none'}}</p>

    <h3>Group</h3>
    <p-dropdown [options]="groupedCars" [(ngModel)]="selectedCar3" [style]="{'width':'150px'}" placeholder="Select a Car" [group]="true">
        <ng-template let-group pTemplate="group">
            <img src="assets/showcase/images/demo/flag/{{group.value}}" style="width:20px;vertical-align:middle" />
            <span style="vertical-align:middle">{{group.label}}</span>
        </ng-template>
    </p-dropdown>
    <p>Selected Car: {{selectedCar3 || 'none'}}</p>
</div>

<div class="content-section documentation">
    <p-tabView effect="fade">
        <p-tabPanel header="Documentation">
            <h3>Import</h3>
<pre>
<code class="language-typescript" pCode ngNonBindable>
import &#123;DropdownModule&#125; from 'primeng/dropdown';
</code>
</pre>

            <h3>Getting Started</h3>
            <p>Dropdown requires a value to bind and a collection of options. There are two alternatives of how to define the options property; one way is providing a collection of SelectItem
            instances whereas other way is providing an array of arbitrary objects along with the optionLabel property to specify the field name of the option. SelectItem API is designed to have more control on how 
            the options are displayed such as grouping and disabling however in most cases an arbitrary object collection will suffice. Example below demonstrates both cases.</p>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;p-dropdown [options]="cities1" [(ngModel)]="selectedCity1"&gt;&lt;/p-dropdown&gt;

&lt;p-dropdown [options]="cities2" [(ngModel)]="selectedCity2" optionLabel="name"&gt;&lt;/p-dropdown&gt;
</code>
</pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
import &#123;SelectItem&#125; from 'primeng/api';

interface City &#123;
  name: string;
  code: string;
&#125;

export class MyModel &#123;

    cities1: SelectItem[];
    
    cities2: City[];

    selectedCity1: City;
    
    selectedCity2: City;

    constructor() &#123;
        //SelectItem API with label-value pairs
        this.cities1 = [
            &#123;label:'Select City', value:null&#125;,
            &#123;label:'New York', value:&#123;id:1, name: 'New York', code: 'NY'&#125;&#125;,
            &#123;label:'Rome', value:&#123;id:2, name: 'Rome', code: 'RM'&#125;&#125;,
            &#123;label:'London', value:&#123;id:3, name: 'London', code: 'LDN'&#125;&#125;,
            &#123;label:'Istanbul', value:&#123;id:4, name: 'Istanbul', code: 'IST'&#125;&#125;,
            &#123;label:'Paris', value:&#123;id:5, name: 'Paris', code: 'PRS'&#125;&#125;
        ];
        
        //An array of cities
        this.cities2 = [
            &#123;name: 'New York', code: 'NY'&#125;,
            &#123;name: 'Rome', code: 'RM'&#125;,
            &#123;name: 'London', code: 'LDN'&#125;,
            &#123;name: 'Istanbul', code: 'IST'&#125;,
            &#123;name: 'Paris', code: 'PRS'&#125;
        ];
    &#125;

&#125;
</code>
</pre>

            <h3>Model Driven Forms</h3>
            <p>Dropdown can be used in a model driven form as well.</p>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;p-dropdown [options]="cities" formControlName="selectedCity"&gt;&lt;/p-dropdown&gt;
</code>
</pre>

            <h3>Filtering</h3>
            <p>Options can be filtered using an input field in the overlay by enabling the filter property. By default filtering is done against
                label of the SelectItem and filterBy property is available to choose one or more properties of the SelectItem API.</p>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;p-dropdown [options]="cities" [(ngModel)]="selectedCity" [filter]="true"&gt;&lt;/p-dropdown&gt;
&lt;p-dropdown [options]="cities" [(ngModel)]="selectedCity" [filter]="true" filterBy="label,value.name"&gt;&lt;/p-dropdown&gt;
</code>
</pre>

            <h3>Grouping</h3>
            <p>Displaying options as grouped is enabled by providing a collection of SelectItemGroup instances and setting group property to true.</p>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;p-dropdown [options]="groupedCars" [(ngModel)]="selectedCar" placeholder="Select a Car" [group]="true"&gt;&lt;/p-dropdown&gt;
</code>
</pre>


<pre>
<code class="language-typescript" pCode ngNonBindable>
import &#123;SelectItem&#125; from 'primeng/api';
import &#123;SelectItemGroup&#125; from 'primeng/api';

export class GroupDemo &#123;
    
    selectedCar: string;

    groupedCars: SelectItemGroup[];

    constructor() &#123;
        this.groupedCars = [
            &#123;
                label: 'Germany', 
                items: [
                    &#123;label: 'Audi', value: 'Audi'&#125;,
                    &#123;label: 'BMW', value: 'BMW'&#125;,
                    &#123;label: 'Mercedes', value: 'Mercedes'&#125;
                ]
            &#125;,
            &#123;
                label: 'USA', 
                items: [
                    &#123;label: 'Cadillac', value: 'Cadillac'&#125;,
                    &#123;label: 'Ford', value: 'Ford'&#125;,
                    &#123;label: 'GMC', value: 'GMC'&#125;
                ]
            &#125;,
            &#123;
                label: 'Japan', 
                items: [
                    &#123;label: 'Honda', value: 'Honda'&#125;,
                    &#123;label: 'Toyota', value: 'Toyota'&#125;
                ]
            &#125;
        ];
    &#125;
&#125;
</code>
</pre>

            <h3>Custom Content</h3>
            <p>Both the selected option and the options list can be templated to provide customization on the default behavior which is displaying label property of an option. Use
                "selectedItem" template to customize the selected label display and the "item" template to change the content of the options in the dropdown panel. In addition when grouping is enabled, "group" template is available 
                to customize the option groups. All templates get the option instance as the default local template variable. 
            </p>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;p-dropdown [options]="cars" [(ngModel)]="selectedCar" [style]="&#123;'width':'150px'&#125;"&gt;
     &lt;ng-template let-item pTemplate="selectedItem"&gt; 
        &lt;img src="assets/showcase/images/demo/car/&#123;&#123;item.label&#125;&#125;.png" style="width:16px;vertical-align:middle" /&gt; 
        &lt;span style="vertical-align:middle"&gt;&#123;&#123;item.label&#125;&#125;&lt;/span&gt;
    &lt;/ng-template&gt; 
    &lt;ng-template let-car pTemplate="item"&gt; 
        &lt;div class="ui-helper-clearfix" style="position: relative;height:25px;"&gt;
        &lt;img src="assets/showcase/images/demo/car/&#123;&#123;car.label&#125;&#125;.png" style="width:24px;position:absolute;top:1px;left:5px"/&gt; 
        &lt;div style="font-size:14px;float:right;margin-top:4px"&gt;&#123;&#123;car.label&#125;&#125;&lt;/div&gt; &lt;/div&gt;
    &lt;/ng-template&gt;
&lt;/p-dropdown&gt;
</code>
</pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
import &#123;SelectItem&#125; from 'primeng/api';

export class MyModel &#123;

    cars: SelectItem[];

    selectedCar: string;

    constructor() &#123;
        this.cars = [
            &#123;label: 'Audi', value: 'Audi'&#125;,
            &#123;label: 'BMW', value: 'BMW'&#125;,
            &#123;label: 'Fiat', value: 'Fiat'&#125;,
            &#123;label: 'Ford', value: 'Ford'&#125;,
            &#123;label: 'Honda', value: 'Honda'&#125;,
            &#123;label: 'Jaguar', value: 'Jaguar'&#125;,
            &#123;label: 'Mercedes', value: 'Mercedes'&#125;,
            &#123;label: 'Renault', value: 'Renault'&#125;,
            &#123;label: 'VW', value: 'VW'&#125;,
            &#123;label: 'Volvo', value: 'Volvo'&#125;,
        ];
    &#125;
&#125;
</code>
</pre>

            <h3>Properties</h3>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Type</th>
                            <th>Default</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>options</td>
                            <td>array</td>
                            <td>null</td>
                            <td>An array of objects to display as the available options.</td>
                        </tr>
                        <tr>
                            <td>optionLabel</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Name of the label field of an option when an arbitrary objects instead of SelectItems are used as options.</td>
                        </tr>
                        <tr>
                            <td>name</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Name of the input element.</td>
                        </tr>
                        <tr>
                            <td>scrollHeight</td>
                            <td>string</td>
                            <td>200px</td>
                            <td>Height of the viewport in pixels, a scrollbar is defined if height of list exceeds this value.</td>
                        </tr>
                        <tr>
                            <td>style</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Inline style of the element.</td>
                        </tr>
                        <tr>
                            <td>panelStyle</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Inline style of the overlay panel element.</td>
                        </tr>
                        <tr>
                            <td>styleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the element.</td>
                        </tr>
                        <tr>
                            <td>panelStyleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the overlay panel element.</td>
                        </tr>
                        <tr>
                            <td>filter</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When specified, displays an input field to filter the items on keyup.</td>
                        </tr>
                        <tr>
                            <td>filterBy</td>
                            <td>string</td>
                            <td>null</td>
                            <td>When filtering is enabled, filterBy decides which field or fields (comma separated) to search against.</td>
                        </tr>
                        <tr>
                            <td>filterPlaceholder</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Placeholder text to show when filter input is empty.</td>
                        </tr>
                        <tr>
                            <td>autoWidth</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Calculates the width based on options width, set to false for custom width.</td>
                        </tr>
                        <tr>
                            <td>required</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When present, it specifies that an input field must be filled out before submitting the form.</td>
                        </tr>
                        <tr>
                            <td>disabled</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When present, it specifies that the component should be disabled.</td>
                        </tr>
                        <tr>
                            <td>editable</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When present, custom value instead of predefined options can be entered using the editable input field.</td>
                        </tr>
                        <tr>
                            <td>appendTo</td>
                            <td>any</td>
                            <td>null</td>
                            <td>Target element to attach the overlay, valid values are "body" or a local ng-template variable of another element.</td>
                        </tr>
                        <tr>
                            <td>tabindex</td>
                            <td>number</td>
                            <td>null</td>
                            <td>Index of the element in tabbing order.</td>
                        </tr>
                        <tr>
                            <td>placeholder</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Default text to display when no option is selected.</td>
                        </tr>
                        <tr>
                            <td>inputId</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Identifier of the focus input to match a label defined for the dropdown.</td>
                        </tr>
                        <tr>
                            <td>dataKey</td>
                            <td>string</td>
                            <td>null</td>
                            <td>A property to uniquely identify a value in options.</td>
                        </tr>
                        <tr>
                            <td>lazy</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>When enabled, creates the dom for options when overlay panel gets visible.</td>
                        </tr>
                        <tr>
                            <td>autofocus</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When present, it specifies that the component should automatically get focus on load.</td>
                        </tr>
                        <tr>
                            <td>resetFilterOnHide</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>Clears the filter value when hiding the dropdown.</td>
                        </tr>
                        <tr>
                            <td>dropdownIcon</td>
                            <td>string</td>
                            <td>fa fa-fw fa-caret-down</td>
                            <td>Icon class of the dropdown icon.</td>
                        </tr>
                        <tr>
                            <td>emptyFilterMessage</td>
                            <td>string</td>
                            <td>No results found</td>
                            <td>Text to display when filtering does not return any results.</td>
                        </tr>
                        <tr>
                            <td>autoDisplayFirst</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Whether to display the first item as the label if no placeholder is defined and value is null.</td>
                        </tr>
                        <tr>
                            <td>group</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>Whether to display options as grouped when nested options are provided.</td>
                        </tr>
                        <tr>
                            <td>showClear</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When enabled, a clear icon is displayed to clear the value.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h3>Events</h3>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Parameters</th>
                        <th>Description</th>
                    </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>onClick</td>
                            <td>event: Click event</td>
                            <td>Callback to invoke when component is clicked.</td>
                        </tr>
                        <tr>
                            <td>onChange</td>
                            <td>event.originalEvent: Browser event<br />
                                event.value: Selected option value
                            </td>
                            <td>Callback to invoke when value of dropdown changes.</td>
                        </tr>
                        <tr>
                            <td>onFocus</td>
                            <td>event: Browser event</td>
                            <td>Callback to invoke when dropdown gets focus.</td>
                        </tr>
                        <tr>
                            <td>onBlur</td>
                            <td>event: Browser event</td>
                            <td>Callback to invoke when dropdown loses focus.</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            
            <h3>Methods</h3>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Parameters</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>resetFilter</td>
                            <td>-</td>
                            <td>Resets filtering.</td>
                        </tr>
                        <tr>
                            <td>focus</td>
                            <td>-</td>
                            <td>Applies focus.</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;p-dropdown #dd [options]="cars" [(ngModel)]="selectedCar" filter="true"&gt;&lt;/p-dropdown&gt;
&lt;button type="button" pButton label="Clear" (click)="clearFilter(dd)"&gt;&lt;/button&gt;
</code>
</pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
clearFilter(dropdown: Dropdown) &#123;
    dropdown.resetFilter();
&#125;
</code>
</pre>

            <h3>Styling</h3>
            <p>Following is the list of structural style classes, for theming classes visit <a href="#" [routerLink]="['/theming']">theming page</a>.</p>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Element</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>ui-dropdown</td>
                            <td>Container element.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-clearable</td>
                            <td>Container element when showClear is on.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-label</td>
                            <td>Element to display label of selected option.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-trigger</td>
                            <td>Icon element.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-panel</td>
                            <td>Icon element.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-items-wrapper</td>
                            <td>Wrapper element of items list.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-items</td>
                            <td>List element of items.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-item</td>
                            <td>An item in the list.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-filter-container</td>
                            <td>Container of filter input.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-filter</td>
                            <td>Filter element.</td>
                        </tr>
                        <tr>
                            <td>ui-dropdown-open</td>
                            <td>Container element when overlay is visible.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h3>Dependencies</h3>
            <p>None.</p>
        </p-tabPanel>

        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/dropdown" class="btn-viewsource" target="_blank">
                <i class="fa fa-github"></i>
                <span>View on GitHub</span>
            </a>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;h3 class="first"&gt;Single&lt;/h3&gt;
&lt;p-dropdown [options]="cities" [(ngModel)]="selectedCity" placeholder="Select a City" optionLabel="name" [showClear]="true"&gt;&lt;/p-dropdown&gt;
&lt;p&gt;Selected City: &#123;&#123;selectedCity ? selectedCity.name : 'none'&#125;&#125;&lt;/p&gt;

&lt;h3&gt;Editable&lt;/h3&gt;
&lt;p-dropdown [options]="cars" [(ngModel)]="selectedCar1" [style]="&#123;'width':'150px'&#125;" editable="true" placeholder="Select a Brand"&gt;&lt;/p-dropdown&gt;
&lt;p&gt;Selected Car: &#123;&#123;selectedCar1 || 'none'&#125;&#125;&lt;/p&gt;

&lt;h3&gt;Content with Filters&lt;/h3&gt;
&lt;p-dropdown [options]="cars" [(ngModel)]="selectedCar2" [style]="&#123;'width':'150px'&#125;" filter="true"&gt;
    &lt;ng-template let-item pTemplate="selectedItem"&gt;
        &lt;img src="assets/showcase/images/demo/car/&#123;&#123;item.label&#125;&#125;.png" style="width:16px;vertical-align:middle" /&gt;
        &lt;span style="vertical-align:middle"&gt;&#123;&#123;item.label&#125;&#125;&lt;/span&gt;
    &lt;/ng-template&gt;
    &lt;ng-template let-car pTemplate="item"&gt;
        &lt;div class="ui-helper-clearfix" style="position: relative;height: 25px;"&gt;
            &lt;img src="assets/showcase/images/demo/car/&#123;&#123;car.label&#125;&#125;.png" style="width:24px;position:absolute;top:1px;left:5px"/&gt;
            &lt;div style="font-size:14px;float:right;margin-top:4px"&gt;&#123;&#123;car.label&#125;&#125;&lt;/div&gt;
        &lt;/div&gt;
    &lt;/ng-template&gt;
&lt;/p-dropdown&gt;
&lt;p&gt;Selected Car: &#123;&#123;selectedCar2||'none'&#125;&#125;&lt;/p&gt;

&lt;h3&gt;Group&lt;/h3&gt;
&lt;p-dropdown [options]="groupedCars" [(ngModel)]="selectedCar3" [style]="&#123;'width':'150px'&#125;" placeholder="Select a Car" [group]="true"&gt;
    &lt;ng-template let-group pTemplate="group"&gt;
        &lt;img src="assets/showcase/images/demo/flag/&#123;&#123;group.value&#125;&#125;" style="width:20px;vertical-align:middle" /&gt;
        &lt;span style="vertical-align:middle"&gt;&#123;&#123;group.label&#125;&#125;&lt;/span&gt;
    &lt;/ng-template&gt;
&lt;/p-dropdown&gt;
</code>
</pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
export class DropdownDemo &#123;

    cities: City[];

    selectedCity: City;

    cars: SelectItem[];

    selectedCar1: string;

    selectedCar2: string = 'BMW';
    
    selectedCar3: string;

    groupedCars: SelectItemGroup[];

    constructor() &#123;
        this.cities = [
            &#123;name: 'New York', code: 'NY'&#125;,
            &#123;name: 'Rome', code: 'RM'&#125;,
            &#123;name: 'London', code: 'LDN'&#125;,
            &#123;name: 'Istanbul', code: 'IST'&#125;,
            &#123;name: 'Paris', code: 'PRS'&#125;
        ];

        this.cars = [
            &#123;label: 'Audi', value: 'Audi'&#125;,
            &#123;label: 'BMW', value: 'BMW'&#125;,
            &#123;label: 'Fiat', value: 'Fiat'&#125;,
            &#123;label: 'Ford', value: 'Ford'&#125;,
            &#123;label: 'Honda', value: 'Honda'&#125;,
            &#123;label: 'Jaguar', value: 'Jaguar'&#125;,
            &#123;label: 'Mercedes', value: 'Mercedes'&#125;,
            &#123;label: 'Renault', value: 'Renault'&#125;,
            &#123;label: 'VW', value: 'VW'&#125;,
            &#123;label: 'Volvo', value: 'Volvo'&#125;
        ];

        this.groupedCars = [
            &#123;
                label: 'Germany', value: 'germany.png', 
                items: [
                    &#123;label: 'Audi', value: 'Audi'&#125;,
                    &#123;label: 'BMW', value: 'BMW'&#125;,
                    &#123;label: 'Mercedes', value: 'Mercedes'&#125;
                ]
            &#125;,
            &#123;
                label: 'USA', value: 'usa.png', 
                items: [
                    &#123;label: 'Cadillac', value: 'Cadillac'&#125;,
                    &#123;label: 'Ford', value: 'Ford'&#125;,
                    &#123;label: 'GMC', value: 'GMC'&#125;
                ]
            &#125;,
            &#123;
                label: 'Japan', value: 'japan.png', 
                items: [
                    &#123;label: 'Honda', value: 'Honda'&#125;,
                    &#123;label: 'Toyota', value: 'Toyota'&#125;
                ]
            &#125;
        ];
    &#125;
&#125;
</code>
</pre>
        </p-tabPanel>
    </p-tabView>
</div>
